<!DOCTYPE html>
<html>
	<head>
		<title>顾客登记</title>
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">

		<%include("/common/include.html"){}%>
	</head>
	<body>
		<p style="height:60px;"></p>
		<div class="content" style=" width: 80%">  
			<%include("/bentryRegister/collectionCustomerInfo.html"){}%>
			 <input id="isdlc"  value="${isdlc !}"/>
			<div id="picture" class="easyui-window" data-options="collapsible:false,minimizable:false,maximizable:false,closable:true,resizable:false" title="查看照片" style="width:300px;height:400px;padding:5px;" closed="true">
				<div class="easyui-layout" data-options="fit:true">
					<div data-options="region:'center'" style="padding:10px;">
						
						<div id="preview">
							
							<img  id="zmpicture" style="height: 100%;width: 100%;" />
							<img  id="cmpicture" style="height: 100%;width: 100%;" />
						</div>
					</div>
				</div>
			</div>
			
			<div class="btnGroup">
				<a href="#" class="easyui-linkbutton"  data-options="iconCls:'icon-save'" onclick="save()" style="width:75px;">保存</a>
				<a id="agreement_button" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-agreement'" onclick="agreement()" style="width:95px;">协议预览</a>
				<a href="#" class="easyui-linkbutton"  data-options="iconCls:'icon-information'" onclick="info()" style="width:95px;">基础资料</a>
			</div>	

		</div>
		<script src="${cxt !}/sb/js/ajaxfileupload.js" type="text/javascript" charset="utf-8"></script>
		<script src="${cxt !}/sb/js/jquery.form.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
		$(document).ready(function () {
			
			
			
			$('#areacodeIds').combobox({
				onChange: function (n,o) {
					$('#agreement_button').show();
					
				
					 var sjtreatment = $('#sjtreatment').textbox('getValue');
					if(n=='27aeb2d41d044394b9b58f6814baa4fa'){//一疗程
						
							$('#cusAgree_treatment').textbox('setValue','1');
							$('#cusAgree_cost').textbox('setValue','760');
						
						
					}else if(n=='0896ce4d4970455d9184e6dd1ced6a0e'){//标准疗程
						
							$('#cusAgree_treatment').textbox('setValue',sjtreatment);
							$('#cusAgree_cost').textbox('setValue',380*sjtreatment);
						
						
					}else if(n=='4777c2c215b6408ab13c1eac4190ce46'){//单疗程
						$('#cusAgree_cost').textbox('setValue','680');
						$('#cusAgree_treatment').textbox('setValue','1');
						$('#agreement_button').hide();
					}else if(n=='0'){//塑性
						$('#cusAgree_cost').textbox('setValue','0');
						$('#cusAgree_treatment').textbox('setValue','0');
						$('#agreement_button').hide();
					}
					
					 $.ajax({
		                cache: true,
		                type: "POST",
		                url:"${cxt !}/bentryRegister/updateTreatment",
		                data:$('#bentryForm').serialize(),// 你的formid
		                dataType:'json',
		                async: false,
		                success: function(result) {
		                	
		                	
		                }
		            });
					 
					
				}
			});
			
			
			
			
			
			
			
			
			var myDate = new Date();    
			 var strDate = myDate.toLocaleDateString();  
			$("#date_input").val(strDate);
			
			var isdlc=$('#isdlc').val();
			if(isdlc == "1")
			{
				$("#agreement_button").hide();
			}
			
			//介绍人信息的隐藏显示
			jsrInfo();
			//省份改变选择城市
			$('#xzqh_select').combobox({

				onChange: function (n,o) {
					getCity(n);
				},
			onSelect: function (n) 
			 {		
				 var newPtion = $('#xzqh_select').combobox('getValue');
				 getCity(newPtion);
			 }

			});
			//市改变选择区
			$('#city_combobox').combobox({

				onChange: function (n,o) {
					getArea(n);
				}
				
			});
			
			
// 			//疗程onchange
// 			lconchange();
		})
		function  jsrInfo()
		{
			var   jdfsval=$('#jdfs_Cus').textbox('getValue');
			if(jdfsval=="转介绍")
			{
				$('#introduce').show();
			}else
			{
				$("#introduce").hide();
			}
			
		}
		function  agreement()
		{	
			var  customerIds=$("#customerIds").val();
			loadDialog(null,null, '协议预览', 'bentryRegister/showAgree?customerIds='+customerIds);
		}
		function  info()
		{
			var  customerIds=$("#customerIds").val();
			var  fzr=$("#fzr").val();		
			loadDialog(null, null,'基础资料', 'bentryRegister/showInfo?customerIds='+customerIds);
		}
		function  save(){	
			var customerIds=$('#customerIds').val();
			var chargePersion_select=$('#chargePersion_select').val();
			if(customerIds != "" )
			{	
				$.ajax({
	                cache: true,
	                type: "POST",
	                url:"${cxt !}/bentryRegister/saveCus",
	                data:$('#bentryForm').serialize(),// 你的formid
	                dataType:'json',
	                async: false,
	                success: function(result) {
	                	
	                	if(result.msg == "200")
	                	{	
	                		 
	                		$("#customerIds").val(result.customerIds);
	                		 $.slideMsg("保存成功", parent.$);
	                		// window.close();
	                		location.replace("${cxt}/collectionBuyProduct");
	                	//	location.reload();
	                	}
	                }
	            });
			}
			else
			{
				 $.alert(parent.$, "顾客信息不能为空！！");
			}
			
		}
		//获取城市
		function  getCity(n)
		{
			var url = "/bentryRegister/getChild";
			var data={"codeIds":n};
			var reData = common_ajax.ajaxFunc(url,data,"json");
			var city=$("#city_input").val();
			var com=$('#city_combobox');
			select(reData,com,city);
		}
		//获取区
		function  getArea(n)
		{
			var url = "/bentryRegister/getChild";
			var data={"codeIds":n};
			var reData = common_ajax.ajaxFunc(url,data,"json");
			var area=$("#area_input").val();
			var com=$('#area_combobox');
			select(reData,com,area);
		}
		function select(reData,com,info)
		{	
			com.combobox({
				  data:reData,
				  valueField:'ids', 
	          	  textField:'name',
		          onLoadSuccess: function () {
		        	  if(info!="")
						 {
							 var val = $(this).combobox('getData'); 
		        	  		  for(var i=0;i<val.length;i++)
		        	  		  {		
		        	  			  if(val[i].ids==info)
		        	  			  {
		        	  				$(this).combobox('select', val[i].ids); 
		        	  			  }
		        	  		  }
						 }else
						 {
							 var val = $(this).combobox('getData');  
	                         for (var item in val[0]) {  
	                             if (item == 'ids') {  
	                                 $(this).combobox('select', val[0][item]);  
	                             }  
	                         } 
						 }
		          }	
	            
			});
			
		}
		
				
		//--------上传图片
		function upload()
		{	
			var customerIds=$('#customerIds').val();
			 $.ajaxFileUpload({
			        url : '${cxt !}/bentryRegister/imageUpload',   //提交的路径
			        secureuri : false, // 是否启用安全提交，默认为false
			        fileElementId :['zmfile','cmfile'], // file控件id
// 					         fileElementId :'zmfile',
			        dataType : 'json',
			        data : {customerIds : customerIds}, // 键:值，传递文件名
			        success : function(result, status) {
			        	if (result.status == 0) {
			        		$.slideMsg("保存成功", parent.$);
// 					                var src = data.src;
// 					                $('#show').append("<img src='" + src + "'>");  //显示图片

// 					                // 存储已上传图片地址
// 					                var oldSrc = $('#pictureSrc').val();
// 					                var newSrc = "";
// 					                if (oldSrc != "")
// 					                    newSrc = oldSrc + ";" + src;
// 					                else
// 					                    newSrc = src;

// 					                $('#pictureSrc').val(newSrc);   //保存路径
			            } 
			        	if(result.status == 1){
			        		
			                $.alert(parent.$, result.message);
			            }
			        	if(result.status == 2)
			        	{
			        		$.slideMsg(result.message, parent.$);
			        	}
			        },
			        error : function(data, status) {
			        	$.alert(parent.$, "只允许上传png,jpg,jpeg,gif,bmp类型的图片文件！");
			        }
			    });
		}
		
		function  imagePreview(obj,type)
		{	
					
			var $file =$(obj);
			var fileObj = $file[0];
			var windowURL = window.URL || window.webkitURL;
			
			var dataURL;
			var $img;
			if(type==1)
			{
				$img = $("#zmpicture");
			}
			if(type==2)
			{
				$img = $("#cmpicture");
			}
// 					var $img = $("#zmpicture");
					 
			if(fileObj && fileObj.files && fileObj.files[0]){
				dataURL = windowURL.createObjectURL(fileObj.files[0]);
				$img.attr('src',dataURL);
			}else{
				dataURL = $file.val();
				var imgObj = document.getElementById("preview");
				// 两个坑:
				// 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
				// 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
				imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
				imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
			}
		}
		function  chakan(type)
		{
			$('#picture').window('open');
			if(type==1)
			{
				$('#zmpicture').css("display","block");
				$('#cmpicture').css("display","none");
			}
			if(type==2)
			{
				$('#zmpicture').css("display","none");
				$('#cmpicture').css("display","block");
			}
		}
				
				
		</script>
	</body>
</html>
